package com.jediflasher.game_server.util.log;

import java.util.Arrays;

/**
 * User: Obi
 * Date: 21.05.11
 * Time: 20:44
 */
public class Logger {

	public static void init() {
		if(_instance == null) {
			_instance = new Logger();
		}else {
			logWarning("Logger already initialized");
		}
	}

	public static void log(String message) {
		if(Logger._instance != null) {
			Logger._instance.l(message);
		}
	}

	public static void log(String message, LogLevel logLevel) {
		if(Logger._instance != null) {
			Logger._instance.l(message, logLevel);
		}
	}

	public static void logInfo(String message) {
		log(message);
	}

	public static void logWarning(String message) {
		log(message, LogLevel.WARNING);
	}

	public static void logError(String message) {
		log(message, LogLevel.ERROR);
	}

	public static void logError(Exception e) {
		log(e.getMessage());
		log(Arrays.toString(e.getStackTrace()));
	}

	private static Logger _instance;

	private Logger() {
		super();
	}

	private void l(String message) {
		this.l(message, LogLevel.INFO);
	}

	private void l(String message, LogLevel logLevel) {
		switch (logLevel) {
			case INFO: this.lInfo(message); break;
			case WARNING: this.lWarning(message); break;
			case ERROR: this.lError(message); break;
		}
	}

	private void lInfo(String message) {
		System.out.println(message);
	}

	private void lWarning(String message) {
		System.out.println("Warning:\n"+message);
	}

	private void lError(String message) {
		System.err.println("Error:\n"+message);
	}
}
